<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日期类型</title>
    <script>
        function fn(){
            // 无参时表示当前时间
            let date = new Date();
            let time = date.getTime();
            // 传递参数时,参数存在顺序,必须是年月日时分秒
            // 可以只传递部分参数,但是只要传递了,必须按照该顺序
            // 不能单独传递一个参数
            // 对于月份,取值范围0~11表示1~12月
            // 对于没有传参的部分,其值均为初始值
            date = new Date(2023,2);
            date = new Date(2023,2,2,15,15,15);

            // 还可以传递一个距离1970年的毫秒数
            date = new Date(time);
            console.log(date);
        }
        function f1(){
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth()+1;
            let day = date.getDate();
            let hours = date.getHours();
            let minute = date.getMinutes();
            let second = date.getSeconds();
            console.log(year+"年"+month+"月"+day+"日"+hours+":"+minute+":"+second);
            let time = date.getTime();
            console.log(time);
            date.setDate(18)
            // 一周第几天,返回0~6,表示周日到周六
            console.log(date.getDay());
        }
        function f2(){
            let date = new Date();
            date.setFullYear(2000);
            date.setMonth(1);
            date.setDate(32);


            let year = date.getFullYear();
            let month = date.getMonth()+1;
            let day = date.getDate();
            let hours = date.getHours();
            let minute = date.getMinutes();
            let second = date.getSeconds();
            console.log(year+"年"+month+"月"+day+"日"+hours+":"+minute+":"+second);

        }
    </script>
</head>
<body>
<button onclick="fn()">定义方式</button><br>
<button onclick="f1()">取值方法</button><br>
<button onclick="f2()">赋值方法</button>
</body>
</html>